package com.scc.services.validation;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.scc.entites.DishEntity;
import com.scc.entites.dto.DishEntityDTO;
import com.scc.persistence.IDishSetupDAO;

@Service
public class ServiceValidator implements IServiceValidator
{
   @Autowired
   private IDishSetupDAO dishSetupDAO;
   
   @Override
   public void validateDTO(DishEntityDTO incomingDTO)
   {
      String code = incomingDTO.getCode();
      if (StringUtils.isEmpty(code))
      {
         throw new ValidationException("Dish code is empty");
      }
      
      DishEntity dish = dishSetupDAO.getDish(code);
      if (null != dish)
      {
         throw new ValidationException("Dish with code: " + code + " already exists");
      }
      
   }
}